package com.myclass.dynamicdatasource.service;

import com.myclass.dynamicdatasource.entity.User;
import com.myclass.dynamicdatasource.mapper.typeone.UserMapper;
import com.myclass.dynamicdatasource.mapper.typetwo.UserTwoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Desc:
 *
 * @author wujw
 * @email jiwenwu@outlook.com
 * @date 2018-12-12
 */
@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private UserTwoMapper userTwoMapper;

    public List<User> getUserOne(){
        return userMapper.getAll();
    }

    public List<User> getUserTwo(){
        return userTwoMapper.getAll();
    }

    public void  insertTypeTwo(User user){
        this.userTwoMapper.insert(user);
    }

    public void insertTypeOne(User user){
        this.userMapper.insert(user);
    }

    public void insertOneAndTwo(User user){
        this.userTwoMapper.insert(user);
        this.userMapper.insert(user);
        System.out.println("===========事务是否生效");
    }

    public List<User> getOneAndTwo(){
        List<User> list1 = this.userMapper.getAll();
        List<User> list2 = this.userTwoMapper.getAll();
        list1.addAll(list2);
        return list1;
    }

}
